# 上传七牛云
from qiniu import Auth, put_file
class QiniuTool:
    q=None
    def __init__(self):
        # 需要填写你的 Access Key 和 Secret Key
        access_key = '_laoL-LQHXAHTmWtqpc9tiJqkSSWVjwOa2FMOnKO'
        secret_key = 'wVXOkJw4UwG71Z0Buj3fiY87zfJIl7mCORDJHHgW'
        # 构建鉴权对象
        self.q = Auth(access_key, secret_key)
    def upload(self,filename):
        # 要上传的空间
        bucket_name = 'p9-w1204-a'
        # 上传后保存的文件名
        key = filename
        # 生成上传 Token，可以指定过期时间等
        token = self.q.upload_token(bucket_name, key, 3600)
        # 要上传文件的本地路径
        localfile = 'static/'+filename
        ret, info = put_file(token, key, localfile, version='v2')
        return ret['key']

